package com.fzfnn.scrapbook.controller;

import com.fzfnn.scrapbook.service.SearchService;
import com.fzfnn.scrapbook.service.UserFollowService;
import com.fzfnn.scrapbook.service.impl.SearchServiceImpl;
import com.fzfnn.scrapbook.util.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/journal/follow")
@Tag(name = "关注接口", description = "关注用户相关接口")
public class UserFollowController {

    @Autowired
    private UserFollowService userFollowService;
    @Autowired
    private SearchService searchService;

    @PostMapping("/add")
    @Operation(summary = "关注用户")
    public R follow(@RequestParam int followedId, @RequestHeader("Authorization") String token) {
        return userFollowService.followUser(token, followedId);
    }

    @PostMapping("/cancel")
    @Operation(summary = "取消关注")
    public R cancel(@RequestParam int followedId, @RequestHeader("Authorization") String token) {
        return userFollowService.unfollowUser(token, followedId);
    }

    @GetMapping("/followed")
    @Operation(summary = "获取我关注的用户")
    public R getFollowed(@RequestHeader("Authorization") String token) {
        return  userFollowService.getFollowedUserIds(token);
    }

    @GetMapping("/fans")
    @Operation(summary = "获取我的粉丝")
    public R getFans(@RequestHeader("Authorization") String token) {
        return userFollowService.getFollowerIds(token) ;
    }

    @GetMapping("/is-following")
    @Operation(summary = "判断用户是否关注")
    public R isFollowing(@RequestHeader("Authorization") String token,
                         @RequestParam Integer followedId) {
        boolean isFollowing = searchService.isUserFollowing(token, followedId);
        return R.successData(isFollowing);
    }
    @GetMapping("/followed-journals")
    @Operation(summary = "获取我关注的用户的手账")
    public R getFollowedJournals(@RequestHeader("Authorization") String token) {
        return userFollowService.getFollowedJournals(token);
    }

}
